SELECT t.*,
  (
  CASE
    WHEN (NOW() BETWEEN IFNULL(T.BEGIN_DATE, NOW()) AND IFNULL(T.END_DATE, NOW()))
    OR (t.state_id IN
      (SELECT w.id
      FROM c1_dictionary w
      WHERE w.code = '1'
      AND EXISTS
        (SELECT 1
        FROM c1_dictionary_type e
        WHERE e.code = 'user_state'
        AND e.id     = w.type_id
        )
      ))
THEN '1'
ELSE '2'
END)
AS valid_code
FROM c1_user t
WHERE (t.code = :code OR EXISTS
  (SELECT 1 FROM eh_mobile_phone_bind e WHERE e.MOBILE_PHONE = :code AND (NOW() BETWEEN IFNULL(e.begin_date, NOW()) AND IFNULL(e.end_date, NOW())) AND e.user_id = t.id
  ))